package com.ssm.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.blog.dao.MessageDAO;
import com.ssm.blog.pojo.Message;
import com.ssm.blog.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDAO messageDAO;

    @Override
    public PageInfo<Message> getMessageList(int pageNum) {
        PageHelper.startPage(pageNum,5);
        List<Message> messages= messageDAO.getMessageList();
        PageInfo<Message> pageInfo=new PageInfo<>(messages,8);
        return pageInfo;
    }

    @Override
    public void addMessage(Message message) {
        message.setCreatedDate(new Date());
        messageDAO.addMessage(message);
    }
}
